<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax请求</title>
</head>

<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<body>
<script type="text/javascript">
	/*页面加载完成之后，执行function里面的代码*/
	$(function() {
		var input=$('input');
		$('#sendAjax').click(function() {
			if (input.val()!=null&&input.val()!="") {
				console.log(input.val());
				// 发送ajax请求
				$.get("../getPost?id="+input.val(), function(data) {
					$('#box').empty();
					console.log(data);
					if (data!=null) {
						var s = "id:" + data.id + " title:" + data.title + " cid:" + data.cid+"\n";
						$('#box').append(s);					
					}else{
						$('#box').append('请求响应出错')
					}
				});
			}
		});
	});
</script>

用户id：<input type="Number" placeholder="输入用户id，仅限数字"><br>
<button id="sendAjax">查看用户信息</button><br>
<div id="box"></div>

</body>
</html>